/**
 * 
 */
package cn.gz.zoomtech.common;

import java.io.FileReader;
import java.io.LineNumberReader;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;





/**
 * 
 * @author Administrator
 *
 */
public class LogTool {
	private static final Log log = LogFactory.getLog(LogTool.class);
	
	
	
	
	public void ExtractionLogDate(String path,String filename){
		
		LineNumberReader reader;
		try{
			reader = new LineNumberReader(new FileReader(path+ filename));	
			String line;
//			UserRegFileReqBody srvReqBody;
			int i=0;
			int startPoint;
			int datePoint;
			String[] dataTempAry;
			String tempdataStr;
		
			while ((line = reader.readLine()) != null) {
				i++;
				try {
//					srvReqBody = new UserRegFileReqBody(line);
					startPoint = line.indexOf("Rec:");
					if(startPoint!=-1){
						line = line.substring(startPoint,line.length());						
//						log.info("line"+i+"*"+startPoint+":"+line);
						datePoint = line.indexOf("[");
						if(datePoint!=-1){
							line = line.substring(datePoint, line.length());							
							dataTempAry = line.split(",");
//							log.info("line"+i+"*"+datePoint+":"+line);
							if(dataTempAry!=null&&dataTempAry.length==6){
								StringBuffer dateline = new StringBuffer();
//								recordSequenceID
								tempdataStr = dataTempAry[4].substring(dataTempAry[4].indexOf("=")+1, dataTempAry[4].length());
								dateline.append(tempdataStr+"\t");
//								mdn
								tempdataStr = dataTempAry[0].substring(dataTempAry[0].indexOf("=")+1, dataTempAry[0].length());
								dateline.append(tempdataStr+"\t");
//								operateType
								tempdataStr = dataTempAry[3].substring(dataTempAry[3].indexOf("=")+1, dataTempAry[3].length());
								dateline.append(tempdataStr+"\t");
//								serviceCapabilityType
								tempdataStr = dataTempAry[5].substring(dataTempAry[5].indexOf("=")+1, dataTempAry[5].length());
								dateline.append(tempdataStr.substring(0,2)+"\t");
//								effectiveDate
								tempdataStr = dataTempAry[1].substring(dataTempAry[1].indexOf("=")+1, dataTempAry[1].length());
								dateline.append(tempdataStr+"\t");
//								expireDate
								tempdataStr = dataTempAry[2].substring(dataTempAry[2].indexOf("=")+1, dataTempAry[2].length());
								dateline.append(tempdataStr);
								
								
								log.info("dateline:"+dateline);	
//								for(int tempK = 0;tempK<dataTempAry.length;tempK++){
//									tempdataStr = str.substring(str.indexOf("=")+1, str.length());
//									if(tempK==6){
//										tempdataStr = tempdataStr.substring(0,2);
//										dateline.append(tempdataStr);
//									}else{
//										dateline.append(tempdataStr+"\t");
//									}
//									
//									log.info("dateline:"+dateline);	
//								}
								
							}
							
						}
						
						
					}
					
					
//					if(i==10){
//						break;
//					}
				} catch (Exception ex) {	
					
					log.error(ex);
					continue;
				}
			} //  end while 循环
			if(reader!=null){
				reader.close();
			}
			
		}catch(Exception ex){
			log.error("error:",ex);
		}finally{
			
		}
	}
	/**
	 * 功能描述: XXXXXXX
	 * @param args
	 * @author chenhui / 2011-3-31 下午01:51:14
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		LogTool lt = new LogTool();
		String path="D:\\work2009\\crbt_vac_user_server\\test\\";
		String filename="date.txt";
		lt.ExtractionLogDate(path, filename);
	}

}
